package cn.tedu;

import java.sql.*;
import java.util.Scanner;

public class Demo09 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入球队名称：");
        String teamName=scan.nextLine();
        //获取连接
        try (Connection conn=DBUtils.getConn()){
            String sql="insert into team values(null,?)";
            PreparedStatement ps=conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.setString(1,teamName);
            ps.executeUpdate();
            //获取装着自增主键值的结果集对象
            ResultSet rs=ps.getGeneratedKeys();
            rs.next();//让游标往下移一格指向查询回来的数据
            int team_id=rs.getInt(1);
            System.out.println("添加完成！id="+team_id);
        } catch (SQLException throwables) {
             throwables.printStackTrace();
        }
    }
}
